<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    private $defaultLocale = 'en';

    /**
     * Set options to session
     */
    protected function _initConfig() {
        Zend_Registry::set('config', new Zend_Config($this->getOptions(), true));
    }

    /**
     * Инициализация переводчика.
     */
    protected function  _initTranslate() {

        $session = new Zend_Session_Namespace('default');

        $localeValue = $session->locale;

        $locale = isset($localeValue) ? new Zend_Locale($localeValue) : new Zend_Locale('auto');
        
        Zend_Registry::set('Zend_Locale', $locale);

        $translationFile = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR
                           . $locale->getLanguage() . '.inc.php';

        if (!file_exists($translationFile)) {
            $translationFile = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR
                               . $this->defaultLocale . '.inc.php';
        }

        $translate = new Zend_Translate('array', $translationFile, $locale->getLanguage());
        Zend_Registry::set('Zend_Translate', $translate);
    }


    /*---------------роуты-----------------*/
    public  function _initRoute(){
        // Получаем маршрут, по-умолчанию
        $router = Zend_Controller_Front::getInstance()->getRouter();
        // маршрут для товаров
        $route_goods = new Zend_Controller_Router_Route(
                '/catalog/:action/:parameter/*',
                array(
                    'controller' => 'account',
                    'action' => 'index'
                ),
                array(
                    'action' => '[\w\-]+',
                    'parameter' => '[\w\-]+'
                )
        );
        $router->addRoute('account', $route_goods);

//        $route_goods = new Zend_Controller_Router_Route(
//                '/catalog/:action/:parameter/*',
//                array(
//                    'controller' => 'account',
//                    'action' => 'userpage'
//                ),
//                array(
//                    'action' => '[\w\-]+',
//                    'parameter' => '[\w\-]+'
//                )
//        );
//        $router->addRoute('account', $route_goods);
    }

}

